<!DOCTYPE html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

	<script type="text/javascript">
		var url;
		function addPassModel(){
			$('#addPassModel').dialog('open').dialog('setTitle','新建口令');
			$('#addPassForm').form('clear');
			url = 'addPass';
		}
        function addPass(){
            $('#addPassForm').form('submit',{
                url: url,
                onSubmit: function(){
                    return $(this).form('validate');
                },
                success: function(rst){
                    var json = eval('('+rst+')');
                    if (json.re){
                        $('#addPassModel').dialog('close');		// close the dialog
                        $('#passtable').datagrid('reload');	// reload the user data
                        $.messager.alert("提示",json.msg)
                    } else {
                        $.messager.show({
                            title: '提示',
                            msg: json.msg
                        });
                    }
                }
            });
        }

		function updatePassModel(){
			var row = $('#passtable').datagrid('getSelected');
			if (row){
				$('#upPassModel').dialog('open').dialog('setTitle','修改口令');
				$('#upPassForm').form('load',row);
				url = 'updatePass';
			}
		}
        function updatePass(){
            $('#upPassForm').form('submit',{
                url: url,
                onSubmit: function(){
                    return $(this).form('validate');
                },
                success: function(rst){
                    var json = eval('('+rst+')');
                    if (json.re){
                        $('#upPassModel').dialog('close');		// close the dialog
                        $('#passtable').datagrid('reload');	// reload the user data
                        $.messager.alert("提示",json.msg)
                    } else {
                        $.messager.show({
                            title: '提示',
                            msg: json.msg
                        });
                    }
                }
            });
        }

		function delPass(){
			var row = $('#passtable').datagrid('getSelected');
			if (row){
				$.messager.confirm('提示','确定删除该口令?',function(r){
					if (r){
                        $.ajax({
                            url: 'delPass',
                            type: 'post',
                            data: {'name': row.name},
                            dataType: "json",
                            success: function (result) {
                                if (result.re){
                                    $('#passtable').datagrid('reload');
                                }else {
                                    $.messager.show({	// show error message
                                        title: '异常',
                                        msg: result.msg
                                    });
                                }
                            }
                        });
					}
				});
			}
		}
	</script>
	
<table id="passtable" title="口令表" class="easyui-datagrid" style="width:550px;height:250px"
        url="getAllPass"
        toolbar="#passtoolbar"
        rownumbers="true" fitColumns="true" singleSelect="true" method="POST" fit="true"
>
    <thead>
        <tr>
            <th field="name" width="100">功能</th>
            <th field="pass" width="120">口令</th>
        </tr>
    </thead>
</table>
<div id="passtoolbar">
    <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addPassModel()">添加口令</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="updatePassModel()">修改口令</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="delPass()">删除口令</a>
</div>





	<style type="text/css">
		#passfm{
			margin:0;
			padding:10px 30px;
		}
		.ftitle{
			font-size:14px;
			font-weight:bold;
			color:#666;
			padding:5px 0;
			margin-bottom:10px;
			border-bottom:1px solid #ccc;
		}
		.fitem{
			margin-bottom:5px;
		}
		.fitem label{
			display:inline-block;
			width:80px;
		}
	</style>

<div id="addPassModel" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"
        closed="true" buttons="#addPassModel-buttons">
    <div class="ftitle">口令信息</div>
    <form id="addPassForm" method="post">
    	<div class="fitem">
            <label>口令功能:</label>
            <input name="name" class="easyui-validatebox" required="true">
        </div>
        <div class="fitem">
            <label>口令:</label>
            <input name="pass" class="easyui-validatebox" required="true">
        </div>
    </form>
</div>
<div id="addPassModel-buttons">
    <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="addPass()">确定</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#addPassModel').dialog('close')">取消</a>
</div>

<div id="upPassModel" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px"
     closed="true" buttons="#upPassModel-buttons">
    <div class="ftitle">口令信息</div>
    <form id="upPassForm" method="post">
        <div class="fitem">
            <label>口令功能:</label>
            <input name="name" class="easyui-validatebox" required="true">
        </div>
        <div class="fitem">
            <label>口令:</label>
            <input name="pass" class="easyui-validatebox" required="true">
        </div>
    </form>
</div>
<div id="upPassModel-buttons">
    <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="updatePass()">确定</a>
    <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#upPassModel').dialog('close')">取消</a>
</div>
